package hlhj.fhp.checkpoint.module

import android.content.Context
import com.example.mymvp.mvp.BaseModule
import com.example.mymvp.okrx.BaseBean
import com.lzy.okgo.model.Response
import hlhj.fhp.checkpoint.http.Apis
import hlhj.fhp.checkpoint.http.CustomAction
import hlhj.fhp.checkpoint.http.LoadingAction
import hlhj.fhp.checkpoint.javaBean.*

/**
 * Created by Never Fear   on 2018\11\6 0006.
Never More....
 */
class HomeModule :BaseModule {

    var listener:HomeResp?=null

    fun deleteCar(id:Int,c:Context){
        Apis.deleteCar(id)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    listener?.deletCar(t.body())
                                }
                            })
                }
    }

    fun getContact(c:Context){
        Apis.getContact()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<ServentBean>>(c){
                                override fun httpSuccess(t: Response<ServentBean>) {
                                    listener?.contactResp(t.body())
                                }
                            })
                }
    }

    fun getCarPages(c: Context){
        Apis.getCarPage()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<CarPageBean>>(c){
                                override fun httpSuccess(t: Response<CarPageBean>) {
                                    listener?.carPageResp(t.body())
                                }
                            })
                }
    }


    fun getBanner(c:Context){
        Apis.getBanner()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<BannerBean>>(c){
                                override fun httpSuccess(t: Response<BannerBean>) {
                                    listener?.bannerResp(t.body())
                                }
                            })
                }
    }

    fun getNotices(c:Context){
        Apis.getNotice()?.let {
            it.doOnSubscribe(LoadingAction(c))
                    .subscribe(object :CustomAction<Response<NoticeBean>>(c){
                        override fun httpSuccess(t: Response<NoticeBean>) {
                            listener?.noticeResp(t.body())
                        }
                    })
        }
    }
    interface HomeResp{
        fun bannerResp(bannerBean: BannerBean)

        fun noticeResp(noticeBean: NoticeBean)

        fun carPageResp(carPageBean: CarPageBean)

        fun contactResp(serventBean: ServentBean)

        fun deletCar(myBaseBean: MyBaseBean)
    }
}